﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjectA.Controls;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;

namespace ProjectA.Modules.Configuracion.Proveedores
{
    public class cWindowProveedores : cWindow
    {
        cProveedores Proveedores;
        wsGeneral.WsGeneral wsGeneral;

        public cWindowProveedores(frmPrincipal frmPrincipal, Point pPoint, Size sSize)
        {
            this.frmPrincipal = frmPrincipal;
            this.BackColor = Color.Transparent;
            this.Location = pPoint;
            this.Size = sSize;
            InitializeComponent();
            InitComponent();

            this.btTabInformacionGen.Checked = true;
            wsGeneral = new ProjectA.wsGeneral.WsGeneral();
            Proveedores = new cProveedores();
            CargarInformacionProveedores();
            //this.VisibleChanged += new System.EventHandler(this.test);
        
        }

        private void test(object sender, EventArgs e)
        {
            this.bnProveedores.Refresh();
            this.lbProveedores.Invalidate();
            this.lbProveedores.Update();
        }

        
        private void tsbImportarProveedores_Click(object sender, EventArgs e)
        {
            DataSet datos = new DataSet();
            datos = Excel.ImportarOrdenesDesdeArchivo();
            wsGeneral.AgregarProveedoresDesdeArchivo(datos);
        }

        private void CargarInformacionProveedores()
        {
            DataSet dsProveedores = new DataSet();
            if (Proveedores.CargarProveedores(out dsProveedores))
            {
                if (dsProveedores.Tables[0].Rows.Count > 0)
                {
                    dsPrincipal.Tables["Proveedores"].Clear();
                    dsPrincipal.Load(dsProveedores.CreateDataReader(), LoadOption.OverwriteChanges, "Proveedores");
                }
                else
                {
                    MessageBox.Show("No ha agregado ningún proveedor", "ProjectA", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }


        #region pInformacionGeneral
        private void btProveedoresActualizar_Click(object sender, EventArgs e)
        {
            Proveedores.NIT = int.Parse(tbProveedoresNIT.Text);
            Proveedores.NombreProveedor = tbProveedoresNombreProveedor.Text;
            Proveedores.NombreContacto = tbProveedoresNombreContacto.Text;
            Proveedores.PaginaWeb = tbProveedoresPaginaWeb.Text;
            Proveedores.Telefono = int.Parse(tbProveedoresTelefono.Text);
            Proveedores.Direccion = tbProveedoresDireccion.Text;
            Proveedores.Email = tbProveedoresCorreoElectronico.Text;
            if (tbProveedorID.Text != "")
                Proveedores.RegistroId = int.Parse(tbProveedorID.Text);

            Proveedores.Actualizar();
            CargarInformacionProveedores();
        }
        #endregion

        #region bnProveedores

        private void tsbProveedoresAgregar_Click(object sender, EventArgs e)
        {
            tbProveedoresNIT.Text = "";
            tbProveedoresNombreProveedor.Text = "";
            tbProveedoresNombreContacto.Text = "";
            tbProveedoresPaginaWeb.Text = "";
            tbProveedoresTelefono.Text = "";
            tbProveedoresDireccion.Text = "";
            tbProveedoresCorreoElectronico.Text = "";
            tbProveedorID.Text = "";
            Proveedores.ModoActual = cProveedores.Modo.Adición;
        }

        private void tsbProveedoresEliminar_Click(object sender, EventArgs e)
        {
            DialogResult DialogResult = new DialogResult();
            DialogResult = MessageBox.Show("¿Está seguro que desea eliminar el proveedor " + tbProveedoresNombreProveedor.Text + " ?", "ProjectA",
               MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (DialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                Proveedores.RegistroId = int.Parse(tbProveedorID.Text);
                Proveedores.Eliminar();
                CargarInformacionProveedores();
            }
        }

        #endregion

        private void btTabInformacionGen_CheckedChanged(object sender, EventArgs e)
        {
            this.btTabInformacionGen.Enabled = false;
        }

        private void InitComponent()
        {
            this.resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPrincipal));
            this.btTabInformacionGen = new cButtonToggle(new Point(338, 22), new Size(153, 39), new EventHandler(btTabInformacionGen_CheckedChanged), Properties.Resources.bt_info_1, Properties.Resources.bt_info_2, Properties.Resources.bt_info_3, Properties.Resources.bt_info_4);
            
            // PanelInformaciónGeneral
            this.pInformacionGeneral.Location = new Point(338,61);

            this.label6 = new cLabel(new Point(34, 62), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "NIT");
            this.label22 = new cLabel(new Point(34, 97), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Proveedor");
            this.label21 = new cLabel(new Point(34, 132), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Nombre de Contacto");
            this.label23 = new cLabel(new Point(34, 167), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Teléfono");
            this.label20 = new cLabel(new Point(34, 202), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Correo Electrónico");
            this.label19 = new cLabel(new Point(34, 235), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Dirección");
            this.label18 = new cLabel(new Point(34, 272), new Size(154, 18), new Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Color.FromArgb(((int)(((byte)(75)))), ((int)(((byte)(117)))), ((int)(((byte)(154))))), ContentAlignment.TopLeft, "Pagina Web");
            this.tbProveedorID = new cTextBox(new Point(181, 375), new Size(1, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedorID.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "ID", true));
            this.tbProveedoresNIT = new cTextBox(new Point(209, 59), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresNIT.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "NIT", true));
            this.tbProveedoresNombreProveedor = new cTextBox(new Point(209, 94), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresNombreProveedor.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "NameProvider", true));
            this.tbProveedoresNombreContacto = new cTextBox(new Point(209, 129), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresNombreContacto.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "NombreContacto", true));
            this.tbProveedoresTelefono = new cTextBox(new Point(209, 164), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresTelefono.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "Telefono", true));
            this.tbProveedoresCorreoElectronico = new cTextBox(new Point(209, 199), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresCorreoElectronico.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "CorreoElectronico", true));
            this.tbProveedoresDireccion = new cTextBox(new Point(209, 234), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresDireccion.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "Direccion", true));
            this.tbProveedoresPaginaWeb = new cTextBox(new Point(209, 270), new Size(208, 25), new Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), null, null);
            this.tbProveedoresPaginaWeb.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProveedores, "PaginaWeb", true));
            this.btProveedoresActualizar = new cButton(new Point(171, 358), new Size(119, 34), new EventHandler(btProveedoresActualizar_Click), Properties.Resources.bt_actualizar_1, Properties.Resources.bt_actualizar_2, Properties.Resources.bt_actualizar_3, Properties.Resources.bt_actualizar_4);

            this.pInformacionGeneral.Controls.Add(this.label6);
            this.pInformacionGeneral.Controls.Add(this.label22);
            this.pInformacionGeneral.Controls.Add(this.label21);
            this.pInformacionGeneral.Controls.Add(this.label23);
            this.pInformacionGeneral.Controls.Add(this.label20);
            this.pInformacionGeneral.Controls.Add(this.label19);
            this.pInformacionGeneral.Controls.Add(this.label18);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresNIT);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresNombreProveedor);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresNombreContacto);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresTelefono);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresCorreoElectronico);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresDireccion);
            this.pInformacionGeneral.Controls.Add(this.tbProveedoresPaginaWeb);
            this.pInformacionGeneral.Controls.Add(this.btProveedoresActualizar);


            this.lbProveedores.Location = new Point(41, 59);
            // BindingNavigator bnProveedores
            #region bindingNavigator1
            this.bnProveedores = new BindingNavigator(new Container());
            this.toolStripButton3 = new ToolStripButton();
            this.toolStripSeparator4 = new ToolStripSeparator();
            this.toolStripTextBox1 = new ToolStripTextBox();
            this.toolStripLabel1 = new ToolStripLabel();
            this.toolStripSeparator5 = new ToolStripSeparator();
            this.toolStripButton4 = new ToolStripButton();
            this.toolStripSeparator6 = new ToolStripSeparator();
            this.tsbProveedoresAgregar = new ToolStripButton();
            this.tsbProveedoresEliminar = new ToolStripButton();
            this.tsbImportarProveedores = new ToolStripButton();
            ((ISupportInitialize)(this.bnProveedores)).BeginInit();
            this.bnProveedores.SuspendLayout();
            // 
            // bnCostosFacturasVer
            // 
            this.bnProveedores.AddNewItem = this.tsbProveedoresAgregar;
            this.bnProveedores.AutoSize = false;
            this.bnProveedores.BindingSource = this.bsProveedores;
            this.bnProveedores.CountItem = this.toolStripLabel1;
            this.bnProveedores.DeleteItem = null;
            this.bnProveedores.Dock = System.Windows.Forms.DockStyle.None;
            this.bnProveedores.Font = new Font("Arial", 11.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            this.bnProveedores.GripMargin = new System.Windows.Forms.Padding(0);
            this.bnProveedores.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.bnProveedores.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButton3,
            this.toolStripSeparator4,
            this.toolStripTextBox1,
            this.toolStripLabel1,
            this.toolStripSeparator5,
            this.toolStripButton4,
            this.toolStripSeparator6,
            this.tsbProveedoresAgregar,
            this.tsbProveedoresEliminar,
            this.tsbImportarProveedores});
            this.bnProveedores.Location = new Point(41, 24);
            this.bnProveedores.MoveFirstItem = null;
            this.bnProveedores.MoveLastItem = null;
            this.bnProveedores.MoveNextItem = this.toolStripButton4;
            this.bnProveedores.MovePreviousItem = this.toolStripButton3;
            this.bnProveedores.Name = "bnProveedores";
            this.bnProveedores.Padding = new System.Windows.Forms.Padding(0);
            this.bnProveedores.PositionItem = this.toolStripTextBox1;
            this.bnProveedores.Size = new Size(260, 30);
            this.bnProveedores.Text = "bindingNavigator1";
            // 
            // toolStripButton3
            // 
            this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton3.Image = ((System.Drawing.Image)(Properties.Resources.bindingNavigatorMovePreviousItem_Image));
            this.toolStripButton3.Name = "toolStripButton3";
            this.toolStripButton3.RightToLeftAutoMirrorImage = true;
            this.toolStripButton3.Size = new System.Drawing.Size(23, 27);
            this.toolStripButton3.Text = "Mover anterior";
            // 
            // toolStripSeparator4
            // 
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            this.toolStripSeparator4.Size = new System.Drawing.Size(6, 30);
            // 
            // toolStripTextBox1
            // 
            this.toolStripTextBox1.AccessibleName = "Posición";
            this.toolStripTextBox1.AutoSize = false;
            this.toolStripTextBox1.Name = "toolStripTextBox1";
            this.toolStripTextBox1.Size = new System.Drawing.Size(50, 23);
            this.toolStripTextBox1.Text = "0";
            this.toolStripTextBox1.ToolTipText = "Posición actual";
            // 
            // toolStripLabel1
            // 
            this.toolStripLabel1.Name = "toolStripLabel1";
            this.toolStripLabel1.Size = new System.Drawing.Size(37, 27);
            this.toolStripLabel1.Text = "de {0}";
            this.toolStripLabel1.ToolTipText = "Número total de elementos";
            // 
            // toolStripSeparator5
            // 
            this.toolStripSeparator5.Name = "toolStripSeparator5";
            this.toolStripSeparator5.Size = new System.Drawing.Size(6, 30);
            // 
            // toolStripButton4
            // 
            this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton4.Image = ((System.Drawing.Image)(Properties.Resources.bindingNavigatorMoveNextItem_Image));
            this.toolStripButton4.Name = "toolStripButton4";
            this.toolStripButton4.RightToLeftAutoMirrorImage = true;
            this.toolStripButton4.Size = new System.Drawing.Size(23, 27);
            this.toolStripButton4.Text = "Mover siguiente";
            // 
            // toolStripSeparator6
            // 
            this.toolStripSeparator6.Name = "toolStripSeparator6";
            this.toolStripSeparator6.Size = new System.Drawing.Size(6, 30);
            // 
            // tsbProveedoresAgregar
            // 
            this.tsbProveedoresAgregar.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tsbProveedoresAgregar.Image = ((System.Drawing.Image)(Properties.Resources.bindingNavigatorAddNewItem_Image)); 
            this.tsbProveedoresAgregar.Name = "tsbProveedoresAgregar";
            this.tsbProveedoresAgregar.RightToLeftAutoMirrorImage = true;
            this.tsbProveedoresAgregar.Size = new System.Drawing.Size(23, 27);
            this.tsbProveedoresAgregar.Text = "Agregar nuevo";
            this.tsbProveedoresAgregar.Click += new System.EventHandler(this.tsbProveedoresAgregar_Click);
            // 
            // tsbProveedoresEliminar
            // 
            this.tsbProveedoresEliminar.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tsbProveedoresEliminar.Image = ((System.Drawing.Image)(Properties.Resources.bindingNavigatorDeleteItem_Image)); 
            this.tsbProveedoresEliminar.Name = "tsbProveedoresEliminar";
            this.tsbProveedoresEliminar.RightToLeftAutoMirrorImage = true;
            this.tsbProveedoresEliminar.Size = new System.Drawing.Size(23, 27);
            this.tsbProveedoresEliminar.Text = "Eliminar";
            this.tsbProveedoresEliminar.Click += new System.EventHandler(this.tsbProveedoresEliminar_Click);
            // 
            // tsbImportarProveedores
            // 
            this.tsbImportarProveedores.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tsbImportarProveedores.Image = global::ProjectA.Properties.Resources.bt_importar;
            this.tsbImportarProveedores.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbImportarProveedores.Name = "tsbImportarProveedores";
            this.tsbImportarProveedores.Size = new System.Drawing.Size(23, 22);
            this.tsbImportarProveedores.Text = "Importar Factura";
            this.tsbImportarProveedores.Click += new System.EventHandler(this.tsbImportarProveedores_Click);
         
            ((System.ComponentModel.ISupportInitialize)(this.bnProveedores)).EndInit();
            this.bnProveedores.ResumeLayout(false);
            this.bnProveedores.PerformLayout();
            #endregion

            this.Controls.Add(this.bnProveedores);
            this.Controls.Add(this.lbProveedores);
            this.Controls.Add(this.pInformacionGeneral);
            this.Controls.Add(this.btTabInformacionGen);
        }

        private DataSets.dsPrincipal dsPrincipal;

        public frmPrincipal frmPrincipal { get; set; }
        private ComponentResourceManager resources;
        public cButtonToggle btTabInformacionGen { get; set; }

        // Controles PanelInformacionGeneral
        public cLabel label6 { get; set; }
        public cLabel label22 { get; set; }
        public cLabel label21 { get; set; }
        public cLabel label23 { get; set; }
        public cLabel label20 { get; set; }
        public cLabel label19 { get; set; }
        public cLabel label18 { get; set; }
        public cTextBox tbProveedorID { get; set; }
        public cTextBox tbProveedoresNIT { get; set; }
        public cTextBox tbProveedoresNombreProveedor { get; set; }
        public cTextBox tbProveedoresNombreContacto { get; set; }
        public cTextBox tbProveedoresTelefono { get; set; }
        public cTextBox tbProveedoresCorreoElectronico { get; set; }
        public cTextBox tbProveedoresDireccion { get; set; }
        public cTextBox tbProveedoresPaginaWeb { get; set; }
        public cButton btProveedoresActualizar { get; set; }

        //bnProveedores
        private BindingNavigator bnProveedores;
        private ToolStripButton tsbProveedoresAgregar;
        private ToolStripLabel toolStripLabel1;
        private ToolStripButton tsbProveedoresEliminar;
        private ToolStripButton toolStripButton3;
        private ToolStripSeparator toolStripSeparator4;
        private ToolStripTextBox toolStripTextBox1;
        private ToolStripSeparator toolStripSeparator5;
        private ToolStripButton toolStripButton4;
        private ToolStripButton tsbImportarProveedores;
        private BindingSource bsProveedores;
        private IContainer components;
        public cListBox lbProveedores;
        private cWindow pInformacionGeneral;
        private ToolStripSeparator toolStripSeparator6;

        //this.lbProveedores = new ListBox();
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.bsProveedores = new System.Windows.Forms.BindingSource(this.components);
            this.dsPrincipal = new ProjectA.DataSets.dsPrincipal();
            this.lbProveedores = new ProjectA.Controls.cListBox();
            this.pInformacionGeneral = new ProjectA.Controls.cWindow();
            ((System.ComponentModel.ISupportInitialize)(this.bsProveedores)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsPrincipal)).BeginInit();
            this.SuspendLayout();
            // 
            // bsProveedores
            // 
            this.bsProveedores.DataMember = "Proveedores";
            this.bsProveedores.DataSource = this.dsPrincipal;
            // 
            // dsPrincipal
            // 
            this.dsPrincipal.DataSetName = "dsPrincipal";
            this.dsPrincipal.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
            // 
            // lbProveedores
            // 
            this.lbProveedores.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.lbProveedores.DataSource = this.bsProveedores;
            this.lbProveedores.DisplayMember = "NameProvider";
            this.lbProveedores.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbProveedores.FormattingEnabled = true;
            this.lbProveedores.IntegralHeight = false;
            this.lbProveedores.Location = new System.Drawing.Point(0, 0);
            this.lbProveedores.Margin = new System.Windows.Forms.Padding(0);
            this.lbProveedores.Name = "lbProveedores";
            this.lbProveedores.Size = new System.Drawing.Size(260, 420);
            this.lbProveedores.TabIndex = 0;
            // 
            // pInformacionGeneral
            // 
            this.pInformacionGeneral.ImageBackGroundPage = null;
            this.pInformacionGeneral.Location = new System.Drawing.Point(0, 0);
            this.pInformacionGeneral.Margin = new System.Windows.Forms.Padding(0);
            this.pInformacionGeneral.Name = "pInformacionGeneral";
            this.pInformacionGeneral.Size = new System.Drawing.Size(460, 422);
            this.pInformacionGeneral.TabIndex = 0;
            ((System.ComponentModel.ISupportInitialize)(this.bsProveedores)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsPrincipal)).EndInit();
            this.ResumeLayout(false);

        }

    }
}
